package main

import (
	"equantum/controller"
	"equantum/middleware"

	"github.com/gin-gonic/gin"
)

func CollectRoute(r *gin.Engine) *gin.Engine {
	r.Use(middleware.CORSMiddleware())

	authRoutes := r.Group("/api/auth")
	authRoutes.POST("/sendvcode", controller.SendVCode)
	authRoutes.POST("/register", controller.Register)
	authRoutes.POST("/login", controller.Login)
	authRoutes.GET("/info", middleware.AuthMiddleware(), controller.Info)

	fileRoutes := r.Group("/api/files")                     // 创建路由分组
	fileRoutes.Use(middleware.AuthMiddleware())             // 用户身份认证中间件
	fileController := controller.NewFileController()        // 创建controller实例
	fileRoutes.POST("/create", fileController.Create)       // 创建文件
	fileRoutes.PUT("/upload/:id", fileController.Upload)    // 上传文件
	fileRoutes.PUT("/save/:id", fileController.Save)        // 写入数据库
	fileRoutes.PUT("/rename/:id", fileController.Update)    // 重命名文件
	fileRoutes.GET("/list", fileController.Show)            // 获取所有文件名
	fileRoutes.GET("/load/:id", fileController.Load)        // 读取文件内容
	fileRoutes.DELETE("/delete/:id", fileController.Delete) // 删除文件

	gateRoutes := r.Group("/api/gates") // 创建路由分组
	gateController := controller.NewGateController()
	gateRoutes.GET("/listbasic", gateController.ShowBasic)

	simulationRoutes := r.Group("/api/simulation") // 创建模拟器路由分组
	simulationRoutes.Use(middleware.AuthMiddleware())
	simulationController := controller.NewSimulationController()
	simulationRoutes.POST("/compile/:id", simulationController.Compile)
	simulationRoutes.POST("/simulate", simulationController.Simulate)

	return r
}
